<!DOCTYPE>
<html lang="en">
<head>
    <meta charset="UTF-8">
<title>烟花效果</title>
<style type="text/css">
<!--
body {
	background-color: #000000;
}
-->
</style></head>

<body>
<script type="text/javascript">
    //自定义变量及数组，并用数组来保存颜色值，在页面中添加多个层，设置其大小、颜色和初始位置
    var col = new Array('#ffffff','#fff000','#ffa000','#ff00ff','#00ff00','#0000ff','#ff0000');
    var p='<div id="rearDiv" style="position:absolute;top:0px;left:0px">';
    var n=0;
    for (var i=0;i<14;++i){
        n++;
        if (n=(col.length-1)) n=0;
        p=p+'<div style="position:relative;width:8px;height:8px;background:'+col[n]+';font-size:3px">.</div>';
    }
    p=p+"</div>";
    document.write(p);
    var Clrs = new Array('#ff0000','#00ff00','#000aff','#ff00ff','#ffa500','#ffff00','#00ff00','#ffffff','#fffff0');
    var sClrs = new Array('#ffa500','#55ff66','#AC9DFC','#fff000','#fffff0');
    var peepY;
    var peepX;
    var step = 5;
    var tallyStep = 0;
    var backColor = '#ffa000';
    var Mtop = 250;
    var Mleft = 250;
    var rearDiv = document.getElementById("rearDiv");
    //自定义函数dissilient()，调用自定义函数enlarge()和reduce()，实现绽放的烟花效果
    function dissilient() {
        peepY = window.document.body.clientHeight/3;
        peepX = window.document.body.clientWidth/8;
        enlarge();
        tallyStep+= step;
        reduce();
        T=setTimeout("dissilient()",20);
    }
    //自定义函数enlarge()，利用正弦值来实现烟花的绽放与缩小
    function enlarge(){
        for (var i = 0 ; i < rearDiv.children.length ; i++) {
            var c=Math.round(Math.random()*(Clrs.length-1));
            if (tallyStep < 90)
                rearDiv.children[i].style.background=backColor;
            if (tallyStep > 90)
                rearDiv.children[i].style.background=Clrs[c];
            rearDiv.children[i].style.top = Mtop + peepY*Math.sin((tallyStep+i*5)/3)*Math.sin(550+tallyStep/100);
            rearDiv.children[i].style.left = Mleft + peepY*Math.cos((tallyStep+i*5)/3)*Math.sin(550+tallyStep/100);
        }
    }
    //自定义函数reduce()，用于改变烟花的绽放位置
    function reduce(){
        if (tallyStep == 220) {
            tallyStep = -10;
            var k=Math.round(Math.random()*(sClrs.length-1));
            backColor = sClrs[k];
            Dtop = window.document.body.clientHeight - 250;
            Dleft = peepX * 3.5;
            Mtop = Math.round(Math.random()*Dtop);
            Mleft = Math.round(Math.random()*Dleft);
            rearDiv.style.top = Mtop+document.body.scrollTop;
            rearDiv.style.left = Mleft+document.body.scrollLeft;
            if ((Mtop < 20) || (Mleft < 20)) {
            Mtop += 90;
            Mleft += 90;
            }
        }
    }
    dissilient();
</script>
</body>
</html>
